package net.adetech.crj.web;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

public class TemplateUtil {

    public static String buildJsonParams(Object... params)
    {
        String result = "";

        for (int i = 0; i < params.length; i+=2) {
            String key = (String) params[i];
            Object value = params[i + 1];
            if (value instanceof Integer || value instanceof Long || value instanceof Double)
            {
                result += ("var "+key+" = "+value+";\n" );
            }
            else if (value instanceof String)
            {
                result += ("var "+key+" = '"+value+"';\n" );
            }
            else if (value instanceof JSONObject)
            {
                result += ("var "+key+" = '"+((JSONObject)value).toJSONString()+"';\n" );
            }
            else {
                result += ("var "+key+" = "+ JSON.toJSONString(value)+";\n" );
            }

        }


        return result;
    }
}
